package com.diyunapp.xilinapp.me;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.main.MainActivity;
import com.diyunapp.xilinapp.selfdefine.StatusBarFragmentActivity;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NoticeContentActivity extends StatusBarFragmentActivity {

    @Bind(R.id.notice_introduce)
    TextView noticeIntroduce;
    @Bind(R.id.go_back1)
    ImageView goBack1;
    @Bind(R.id.title)
    TextView title1;
    @Bind(R.id.company_link)
    WebView companyLink;
    private String id;
    private String title;
    private LayoutInflater inflater;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice_content);
        inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

        ButterKnife.bind(this);
        View headView;
        headView = findViewById(R.id.ntco_menubar_inc);
        super.MenuWidget(headView);
        id = getIntent().getExtras().getString("article_id");

        initNotice();

    }

    public void initNotice() {
        String url = "" + MainActivity.url + "act=goods&op=list_detail&article_id=" + id + "";
        Log.i("zhangxiaoxidebug", "url=" + url);
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(10000);
        http.send(HttpRequest.HttpMethod.POST, url,
                new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
//                        bidFreshLv.onRefreshComplete();
                        String resultinfo = responseInfo.result;
                        Log.i("zhangxiaoxidebug", "resultinfo=" + resultinfo);
//                        Logger.e("=================================="+resultinfo);
                        try {
                            JSONObject resultObject = new JSONObject(resultinfo);
                            int result = resultObject.optInt("code");

                            if (result == 200) {
                                JSONObject recordObject = resultObject.optJSONObject("data");


                                String article_content = recordObject.optString("article_content");
                                String article_time = recordObject.optString("article_time");
//                                noticeIntroduce.setText("  " + article_content);
                                companyLink.getSettings().setDefaultTextEncodingName("UTF-8") ;
                                companyLink.loadDataWithBaseURL(null, article_content, "text/html","UTF-8", null);

                            } else {
                                toast("当前暂无数据");


                            }
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            toast("查询失败");
                            e.printStackTrace();

                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {

                        toast("请求失败");

                    }
                });
    }

    @OnClick(R.id.go_back1)
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.go_back1:
                finish();
                break;
        }
    }
}
